package com.hlx.service.admin.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hlx.entity.admin.Administrator;
import com.hlx.mapper.admin.AdministratorMapper;
import com.hlx.service.admin.AdministratorService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class AdministratorServiceImpl extends ServiceImpl<AdministratorMapper,Administrator> implements AdministratorService {

    @Override
    public Administrator login(Administrator administrator) {
        LambdaQueryWrapper<Administrator> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Administrator::getAdministratorAccount,administrator.getAdministratorAccount());
        Administrator admin = this.getOne(queryWrapper);
        if(admin.getAdministratorPassword().equals(DigestUtils.md5DigestAsHex(administrator.getAdministratorPassword().getBytes()))){
            return admin;
        }
        return null;
    }
}
